# -*- coding: utf-8 -*-

from __future__ import division

import random

class Action:
  def apply(self, player, game): pass

class Move:
  def __init__(self, direction, coefficient = None, distance = None):
    if distance == None: distance = 10000
    if coefficient == None: coefficient = 1
    if coefficient < 0 or coefficient > 1: coefficient %= 1
    self.direction   = direction
    self.orientation = direction.clone()
    self.coefficient = coefficient
    self.distance    = distance

  def apply(self, player, game):
    player.location.move(self.direction, self.coefficient)
    player.orientation = self.orientation

class Intercept:
  def __init__(self): self.success = True

  def apply(self, player, game):
    if game.ballOwner == None:
      self.success = True
    player.hasTheBall = self.success
    if self.success:
      if game.ballOwner != None:
        game.ballOwner.hasTheBall = False
      game.setBallOwner(player)

class Shoot:
  def apply(self, player, game):
    if not player.hasTheBall: return
    player.hasTheBall = False
    game.setBallOwner(None)
    game.ball.shoot(game.field.width * 9 / 50, player.orientation)
